import * as React from "react";
import PropTypes from 'prop-types';
import {RwCode, RwCodeArray} from '../../pages/home/toupiao/const/Const';

import DYZIcon from '../../assets/icon/vote/ywh/dyz.png';
import DZIcon from '../../assets/icon/vote/ywh/dz.png';
import WYIcon from '../../assets/icon/vote/ywh/wy.png';
import ZRIcon from '../../assets/icon/vote/ywh/zr.png';

import {Link} from "react-keeper";

import {Badge, Flex, List} from "antd-mobile";
const Item = List.Item;
const Brief = Item.Brief;

export default class YwhtpItem extends React.Component {

  constructor(props) {
    super(props);
  }

  render() {

    let icon;
    let content;
    switch (this.props.rw.rwCode) {
      case RwCode.CAST01:
        icon = DYZIcon;
        content = <span style={{marginRight: '10px'}}>{this.props.courtName + '-' + this.props.rw.building + '栋' + this.props.rw.unit + '单元'}</span>;
        break;
      case RwCode.CAST02:
        icon = DZIcon;
        content = <span style={{marginRight: '10px'}}>{this.props.courtName + '-' + this.props.rw.building + '栋'}</span>;
        break;
      case RwCode.CAST03:
        icon = WYIcon;
        content = <span style={{marginRight: '10px'}}>{this.props.courtName}</span>;
        break;
      case RwCode.CAST04:
        icon = ZRIcon;
        content = <span style={{marginRight: '10px'}}>{this.props.courtName}</span>;
        break;
      default:
        content = null;
        break;
    }
    return (
      content &&
      <Flex>
        <Flex.Item style={{ padding: '0 0 0 15px', color: '#888', flex: 'none' }}>
          <img src={icon} style={{width: '48px', height: '48px'}} />
        </Flex.Item>
        <Flex.Item>
          <Link to={`/home/ywh/t/${this.props.rw.rwCode}`} state={{...this.props.rw}}>
            <Item
              arrow="horizontal"
              multipleLine
              onClick={() => {}}>
              {content}<Badge text={ this.props.rw.voted ? '已投' : '未投'} />
              <Brief>{this.props.rw.rwName + '候选人'}</Brief>
            </Item>
          </Link>
        </Flex.Item>
      </Flex>
    )
  }
}

YwhtpItem.propTypes = {
  rw: PropTypes.arrayOf(
    PropTypes.shape({
      rwId: PropTypes.string.isRequired,
      rwCode: PropTypes.oneOf(RwCodeArray).isRequired,
      startTime: PropTypes.string.isRequired,
      endTime: PropTypes.string.isRequired,
      courtId: PropTypes.string.isRequired,
      building: PropTypes.string.isRequired,
      unit: PropTypes.string.isRequired,
      isVoted: PropTypes.bool.isRequired
    }).isRequired
  ).isRequired
};
